package com.scalar.chiptrack.sales;

import com.scalar.chiptrack.utils.StringUtils;
import com.scalar.chiptrack.commons.Constants;

import java.net.URLEncoder;
import java.io.UnsupportedEncodingException;
import java.util.Calendar;
import java.util.ArrayList;

import org.apache.struts.util.LabelValueBean;

/**
 * Author: Sharath
 * Date: Jan 28, 2004
 * Time: 22:30:00
 */

/**
 *  Sales Order Invoice object captures all the values of a Sales Order
 *  This class is used to assign and retrieve values from the variables.
 *
 *  @author Sharath
 *  @version
 */

public class SalesOrderInvoice
{
    // Sales Order Invoice Related variables
    private int     mInvoiceDocumentTypeId;             // Stores Sales Invoice Document Type
    private String  mInvoiceDocumentTypeIdLabel;        // Stores Sales Invoice Document Type Label
    private String  mInvoiceNumber;                     // Stores the Sales Invoice Number
    private String  mBatchNumber;                       // Stores the Batch Number
    private String  mBatchSource;                       // Stores Batch Source information
    private String  mPackingSlipNumber;                 // Stores the Packing Slip information
    private int     mCustomerId;                        // Stores Customer ID information
    private String  mCustomerNumber;                    // Stores Customer Number information
    private String  mCustomerName;                      // Stores Customer Name information
    private String  mCustomerPONumber;                  // Stores Custoemr PO No Information
    private String  mPostingDate;                       // Stores Invoice Posting date information
    private String  mDocumentDate;                      // Stores Document Date information
    private String  mQuotedDate;                        // Stores Quote Date information
    private String  mOrderDate;                         // Stores Order Date information
    private boolean mHold;                              // Stores Hold information
    private String  mLocationCode;                      // Stores Location Information
    private String  mCommentId;                         // Stores Comment Id Information.
    private String  mCommentDescription;                // Stores Comment Description Information
    // Amounts Info
    private double  mDocumentAmount;                    // Stores Document Amount Information
    private double  mTotal;                             // Stores the Total Information
    private double  mSubTotal;                          // Stores the Sub Total Information
    private double  mFreight;                           // Stores Freight information
    private double  mMiscellaneous;                     // Stores Miscellaneous information
    private double  mTax;                               // Stores Tax information
    private double  mTradeDiscount;                     // Stores Trade Discount information
    private double  mAccountAmount;                     // Stores Account Amount information
    private double  mAmountReceived;                    // Stores Amount Received Information
    private double  mDiscountTaken;                     // Stores Discount Taken Information

    private int     mFreightTaxable;                    // Stores the Freight taxable or not information
    private String  mFreightId;                         // Stores the Freight Id Information
    private int     mMiscellaneousTaxable;              // Stores the Miscellaneous Taxable or not Information
    private String  mMiscellaneousId;                   // Stores the Miscellaneous Id Information

    // Added by Devi on 13 March 2004 to get and set Quote Number and Sales order Number in and from database
    private String  mQuoteNumber;                       // Stores the Quote Number
    private String  mSalesOrderNumber;                  // Stores the sales order number

    // Added on March 21 00:35
    private String mSelectedSONumber;               // Stores the SO number selected by the user.

    private SalesOrderInvoiceLineItemList mSalesOrderInvoiceLineItemList;

    private String mYear = Integer.toString ( Calendar.getInstance ().get ( Calendar.YEAR ) );

    public SalesOrderInvoice()
    {
        mInvoiceDocumentTypeId      = 0;
        mInvoiceDocumentTypeIdLabel = "";
        mInvoiceNumber              = "";
        mBatchNumber                = "";
        mBatchSource                = "";
        mPackingSlipNumber          = "";
        mCustomerId                 = -1;
        mCustomerNumber             = "";
        mCustomerName               = "";
        mCustomerPONumber           = "";
        mPostingDate                = "";
        mDocumentDate               = "";
        mQuotedDate                 = "";
        mOrderDate                  = "";
        mHold                       = false;
        mLocationCode               = "";
        mCommentId                  = "";
        mCommentDescription         = "";
        mDocumentAmount             = 0.00;
        mTotal                      = 0.00;
        mSubTotal                   = 0.00;
        mFreight                    = 0.00;
        mMiscellaneous              = 0.00;
        mTax                        = 0.00;
        mTradeDiscount              = 0.00;
        mAccountAmount              = 0.00;
        mAmountReceived             = 0.00;
        mDiscountTaken              = 0.00;
        mFreightTaxable             = 0;
        mFreightId                  = "";
        mMiscellaneousTaxable       = 0;
        mMiscellaneousId            = "";
        mQuoteNumber                = "";
        mSalesOrderNumber           = "";
        mSelectedSONumber           = "";

        mSalesOrderInvoiceLineItemList   = new SalesOrderInvoiceLineItemList();
        mYear                       = Integer.toString ( Calendar.getInstance ().get ( Calendar.YEAR ) );
    }

    public int getInvoiceDocumentTypeId()
    {
        return mInvoiceDocumentTypeId;
    }

    public void setInvoiceDocumentTypeId( int invoiceDocumentTypeId )
    {
        mInvoiceDocumentTypeId = invoiceDocumentTypeId;
    }

    public String getInvoiceDocumentTypeIdLabel()
    {
        return mInvoiceDocumentTypeIdLabel;
    }

    public void setInvoiceDocumentTypeIdLabel( String invoiceDocumentTypeIdLabel )
    {
        mInvoiceDocumentTypeIdLabel = invoiceDocumentTypeIdLabel;
    }

    public String getInvoiceNumber()
    {
        return mInvoiceNumber;
    }

    public void setInvoiceNumber( String invoiceNumber )
    {
        mInvoiceNumber = invoiceNumber;
    }

    public String getBatchNumber()
    {
        return mBatchNumber;
    }

    public void setBatchNumber( String batchNumber )
    {
        mBatchNumber = batchNumber;
    }

    public String getBatchSource()
    {
        return mBatchSource;
    }

    public void setBatchSource( String batchSource )
    {
        mBatchSource = batchSource;
    }

    public String getPackingSlipNumber()
    {
        return mPackingSlipNumber;
    }

    public void setPackingSlipNumber( String packingSlipNumber )
    {
        mPackingSlipNumber = packingSlipNumber;
    }

    public int getCustomerId()
    {
        return mCustomerId;
    }

    public void setCustomerId( int customerId )
    {
        mCustomerId = customerId;
    }

    public String getCustomerName()
    {
        return mCustomerName;
    }

    public void setCustomerName( String customerName )
    {
        mCustomerName = customerName;
    }

    public String getCustomerPONumber()
    {
        return mCustomerPONumber;
    }

    public void setCustomerPONumber( String customerPONumber )
    {
        mCustomerPONumber = customerPONumber;
    }

    public String getPostingDate()
    {
        return mPostingDate;
    }

    public void setPostingDate( String postingDate )
    {
        mPostingDate = postingDate;
    }

    public String getDocumentDate()
    {
        return mDocumentDate;
    }

    public void setDocumentDate( String documentDate )
    {
        mDocumentDate = documentDate;
    }

    public String getQuotedDate()
    {
        return mQuotedDate;
    }

    public void setQuotedDate( String quotedDate )
    {
        mQuotedDate = quotedDate;
    }

    public String getOrderDate()
    {
        return mOrderDate;
    }

    public void setOrderDate( String orderDate )
    {
        mOrderDate = orderDate;
    }

    public boolean isHold()
    {
        return mHold;
    }

    public void setHold( boolean hold )
    {
        mHold = hold;
    }

    public String getLocationCode()
    {
        return mLocationCode;
    }

    public void setLocationCode( String locationCode )
    {
        mLocationCode = locationCode;
    }

    public String getCommentId()
    {
        return mCommentId;
    }

    public void setCommentId( String commentId )
    {
        mCommentId = commentId;
    }

    public String getCommentDescription()
    {
        return mCommentDescription;
    }

    public void setCommentDescription( String commentDescription )
    {
        mCommentDescription = commentDescription;
    }

    public double getDocumentAmount()
    {
        return mDocumentAmount;
    }

    public void setDocumentAmount( double documentAmount )
    {
        mDocumentAmount = documentAmount;
    }

     public String getSubTotalAsString()
    {
        return StringUtils.formatAmount( mSubTotal, "$###,###.##" );
    }

    public double getSubTotal()
    {
        return mSubTotal;
    }

    public void setSubTotal( double subTotal )
    {
        mSubTotal = subTotal;
    }

    public String getTotalAsString()
    {
        return StringUtils.formatAmount( mTotal, "$###,###.##" );
    }

    public double getTotal()
    {
        return mTotal;
    }

    public void setTotal( double total )
    {
        mTotal = total;
    }

    public String getTradeDiscountAsString()
    {
        return StringUtils.formatAmount( mTradeDiscount, "$###,###.##" );
    }

    public double getTradeDiscount()
    {
        return mTradeDiscount;
    }

    public void setTradeDiscount( double tradeDiscount )
    {
        mTradeDiscount = tradeDiscount;
    }

    public String getAccountAmountAsString()
    {
        return StringUtils.formatAmount( mAccountAmount, "$###,###.##" );
    }

    public double getAccountAmount()
    {
        return mAccountAmount;
    }

    public void setAccountAmount( double accountAmount )
    {
        mAccountAmount = accountAmount;
    }

    public String getAmountReceivedAsString()
    {
        return StringUtils.formatAmount( mAmountReceived, "$###,###.##" );
    }

    public double getAmountReceived()
    {
        return mAmountReceived;
    }

    public void setAmountReceived( double amountReceived )
    {
        mAmountReceived = amountReceived;
    }

    public String getDiscountTakenAsString()
    {
        return StringUtils.formatAmount( mDiscountTaken, "$###,###.##" );
    }

    public double getDiscountTaken()
    {
        return mDiscountTaken;
    }

    public void setDiscountTaken( double discountTaken )
    {
        mDiscountTaken = discountTaken;
    }

    public String getFreightAsString()
    {
        return StringUtils.formatAmount( mFreight, "$###,###.##" );
    }

    public double getFreight()
    {
        return mFreight;
    }

    public void setFreight( double freight )
    {
        mFreight = freight;
    }

    public String getMiscellaneousAsString()
    {
        return StringUtils.formatAmount( mMiscellaneous, "$###,###.##" );
    }

    public double getMiscellaneous()
    {
        return mMiscellaneous;
    }

    public void setMiscellaneous( double miscellaneous )
    {
        mMiscellaneous = miscellaneous;
    }

    public String getTaxAsString()
    {
        return StringUtils.formatAmount( mTax, "$###,###.##" );
    }

    public double getTax()
    {
        return mTax;
    }

    public void setTax( double tax )
    {
        mTax = tax;
    }

    public SalesOrderInvoiceLineItemList getSalesOrderInvoiceLineItemList()
    {
        return mSalesOrderInvoiceLineItemList;
    }

    public void setSalesOrderInvoiceLineItemList( SalesOrderInvoiceLineItemList salesOrderInvoiceLineItemList )
    {
        mSalesOrderInvoiceLineItemList = salesOrderInvoiceLineItemList;
    }

    public int getFreightTaxable()
    {
        return mFreightTaxable;
    }

    public void setFreightTaxable( int freightTaxable )
    {
        mFreightTaxable = freightTaxable;
    }

    public String getFreightId()
    {
        return mFreightId;
    }

    public void setFreightId( String freightId )
    {
        mFreightId = freightId;
    }

    public int getMiscellaneousTaxable()
    {
        return mMiscellaneousTaxable;
    }

    public void setMiscellaneousTaxable( int miscellaneousTaxable )
    {
        mMiscellaneousTaxable = miscellaneousTaxable;
    }

    public String getMiscellaneousId()
    {
        return mMiscellaneousId;
    }

    public void setMiscellaneousId( String miscellaneousId )
    {
        mMiscellaneousId = miscellaneousId;
    }
    /*
    * set and get methods added by devi on 13 March 2004
    * to retrieve and store Quote Number and Sales order Number
    * values from and to the database.
    */

    public String getQuoteNumber()
    {
        return mQuoteNumber;
    }

    public void setQuoteNumber( String quoteNumber )
    {
        mQuoteNumber = quoteNumber;
    }

    public String getSalesOrderNumber()
    {
        return mSalesOrderNumber;
    }

    public void setSalesOrderNumber( String salesOrderNumber)
    {
        mSalesOrderNumber = salesOrderNumber;
    }


    public void addSalesOrderInvoiceLineItem( SalesOrderInvoiceLineItem salesOrderInvoiceLineItem )
    {
        mSalesOrderInvoiceLineItemList.add( salesOrderInvoiceLineItem );
    }

    public String getSelectedSONumber()
    {
        return mSelectedSONumber;
    }

    public void setSelectedSONumber( String selectedSONumber )
    {
        mSelectedSONumber = selectedSONumber;
    }

    public String getCustomerNumber()
    {
        return mCustomerNumber;
    }

    public void setCustomerNumber( String customerNumber )
    {
        this.mCustomerNumber = customerNumber;
    }

    public String getYear()
    {
        return mYear;
    }

    public void setYear(String year)
    {
        this.mYear = year;
    }

    /**
     * returns the URL encoded Sales Invoice No
     * @return String
     */
    public String getEncodedSalesInvoiceNumber()
    {
        try
        {
            return URLEncoder.encode( mInvoiceNumber , "UTF-8" );
        }
        catch ( UnsupportedEncodingException use )
        {
            return mInvoiceNumber;
        }
    }

    public static ArrayList getYearList()
    {
        int start_year = Constants.YEAR_START;
        int end_year = Constants.YEAR_END;

        ArrayList yearList = new ArrayList ();
        for ( int year = start_year; year <= end_year; year++ )
        {
            yearList.add ( new LabelValueBean ( year + "", year + "" ) );
        }
        return yearList;
    }
}
